package com.iron.common.log;

import com.iron.common.log.aspect.SysLogAspect;
import com.iron.common.log.event.SysLogListener;
import com.iron.sfm.api.feign.SysLogFeign;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * 日志自动配置
 *
 * @author YT
 * @date 2019-06-27
 */
@EnableAsync
@Configuration
@AllArgsConstructor
@ConditionalOnWebApplication
@EnableFeignClients({"com.iron.sfm.api.feign"})
public class LogAutoConfiguration {

    private final SysLogFeign sysLogFeign;

    @Bean
    public SysLogListener sysLogListener(){
        return new SysLogListener(sysLogFeign);
    }

    @Bean
    public SysLogAspect sysLogAspect(ApplicationEventPublisher publisher){
        return new SysLogAspect(publisher);
    }
}
